//
//
//  网络料单界面
//
//

import QtQuick
import QtQuick.Layouts
import QtQuick.Controls.Material
import Qt5Compat.GraphicalEffects


Item {
    id: netWorkProcessBack
    width: rootWidth
    height: rootHeight /*- 150*/

    property bool completionDialogShown: false
    property bool autoWrapEnabled: false  // 自动换行功能开关状态

    // 计数相关变量
    property bool plc_M61: Cpp_PLC.NetWork_M61      // 工进动作
    property bool plc_M96: Cpp_PLC.NetWork_M96      // 超长加工
    property bool plc_M97: Cpp_PLC.NetWork_M97      // 超短加工
    property bool plc_X_13: Cpp_PLC.IO_X13          // 锯片后位



    Component.onCompleted: {
        Cpp_PLC.QML_CurrentPage = 7;
        Cpp_PLC.write_Modbus_RTU_Hold_16(48,"3")
        Cpp_PLC.write_Modbus_RTU_Coils(142,"1")
        cutDataModel.readFromCsv(); // 加载上次保存的数据
    }

    Component.onDestruction: {
        cutDataModel.saveToCsv()
    }

    Dialog {
        id: completionDialog
        title: qsTr("提示")
        width: 600
        height: 800
        x: (netWorkProcessBack.width - width) /2
        y: (netWorkProcessBack.height - height) / 2
        // text: qsTr("当前料单已经全部加工完成")
        visible: false
        modal: true  // 模态窗口，阻止其他操作
        closePolicy: Popup.NoAutoClose
        // 去掉默认按钮栏
        standardButtons: Dialog.NoButton

        // 内容区域布局
        contentItem:
            // 提示文本 - 居中显示
            Text {
                text: qsTr("当前料单已全部加工完成!!")
                font.pixelSize: 30
                color: "#333333"
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.verticalCenter: parent.verticalCenter
                // 确保文本在对话框中垂直居中
                // Column.layout.alignment: Qt.AlignCenter
            }


        // 自定义确定按钮 - 右下角
        Button {
            id: confirmButton
            text: qsTr("确定")
            width: 200
            height: 60
            font.pixelSize: 20
            font.bold: true

            // 定位到右下角
            anchors.bottom: parent.bottom
            anchors.right: parent.right
            anchors.bottomMargin: 20
            anchors.rightMargin: 20

            // 按钮样式
            background: Rectangle {
                color: confirmButton.pressed ? "#2980b9" : "#3498db"
                border.color: "#2980b9"
                border.width: 2
                radius: 8
            }

            // 文字样式
            contentItem: Text {
                text: confirmButton.text
                color: "white"
                font: confirmButton.font
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
            }

            // 点击事件
            onClicked: {
                completionDialog.visible = false;
                completionDialogShown = false;
            }
        }
    }

    Item{
        anchors.top: netWorkProcessBack.top
        anchors.horizontalCenter: netWorkProcessBack.horizontalCenter
        width: 1080
        height: 1585

        // 表格背景
        Rectangle{
            anchors.fill: parent
            border.width: 1
        }

        // 表格标题栏（颜色列宽度调整为140）
        Row {
            id: headerRow
            anchors.top: parent.top
            anchors.left: parent.left
            anchors.right: parent.right
            height: 60
            z:10

            Rectangle {width: 70;height: parent.height;border.color: "#cccccc";
                Text {anchors.centerIn: parent;font.bold: true;font.pixelSize: 15;
                    text: qsTr("序 号"); } }
            Rectangle { width: 120; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("订单编号") } }
            Rectangle { width: 90; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("型材类型") } }
            Rectangle { width: 120; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("产品名称") } }
            Rectangle { width: 140; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("颜色") } }
            Rectangle { width: 80; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("原料长度") } }
            Rectangle { width: 140; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("切割长度") } }
            Rectangle { width: 70; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("左角度") } }
            Rectangle { width: 70; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("右角度") } }
            Rectangle { width: 90; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("切割数量") } }
            Rectangle { width: 90; height: parent.height; border.color: "#cccccc";
                Text { anchors.centerIn: parent; font.bold: true; font.pixelSize: 15;
                    text: qsTr("已切数量") } }
        }

        // 表格项目
        ListView {
            id: listView
            anchors.top: headerRow.bottom
            anchors.left: parent.left
            anchors.right: parent.right
            height: 1525
            // anchors.bottom: parent.bottom  // 与listArea底部绑定，高度自适应
            model: cutDataModel
            spacing: 1
            clip: true
            // 禁用拖动超出边界的效果（到达边界后停止）
            boundsBehavior: Flickable.StopAtBounds

            Connections {
                target: cutDataModel
                function onModelDataUpdated() {
                    // 模型数据更新时，检查保存的索引是否仍有效
                    if (Cpp_PLC.NetWork_CurrentIndex >= cutDataModel.count) {
                        Cpp_PLC.NetWork_CurrentIndex = -1;  // 索引无效时重置
                    }
                    listView.currentIndex = -1;  // 保持原有逻辑：数据更新时取消选中
                    console.log("模型数据更新，重置currentIndex");
                }
            }


            // 检查当前行是否完成
            function checkComplete(rowIndex) {
                if (rowIndex < 0 || rowIndex >= cutDataModel.count) return false;
                const item = cutDataModel.get(rowIndex);
                return item.cutCount === item.workedCount && item.cutCount !== 0;
            }

            // 查找下一个未完成的行（核心修改）
            function findNextValidRow(startIndex) {
                // 从startIndex+1开始查找
                for (let i = startIndex + 1; i < cutDataModel.count; i++) {
                    if (!checkComplete(i)) {
                        return i; // 返回第一个未完成的行索引
                    }
                }
                return -1; // 未找到有效行
            }

            // 自动移动到下一个有效行（跳过已完成行）
            function moveToNextValidRow(currentIndex) {
                // 查找下一个未完成的行
                const nextIndex = findNextValidRow(currentIndex);

                if (nextIndex !== -1) {
                    // 找到有效行，移动到该行
                    listView.currentIndex = nextIndex;
                    console.log("自动跳过已完成行，移动到第" + (nextIndex + 1) + "行");
                } else {
                    // 未找到有效行，检查是否全部完成
                    listView.currentIndex = -1;
                    console.log("后续无有效行，取消选中");
                    checkAndShowCompletionDialog();
                }
            }

            // 检查所有行是否都已完成
            function checkAllComplete() {
                if (cutDataModel.count === 0) return false;
                for (let i = 0; i < cutDataModel.count; i++) {
                    if (!checkComplete(i)) {
                        return false;
                    }
                }
                return true;
            }

            // 检查并显示完成弹窗
            function checkAndShowCompletionDialog() {
                if (checkAllComplete() && !completionDialogShown) {
                    completionDialog.visible = true;
                    completionDialogShown = true;
                }
            }

            onCurrentIndexChanged: {
                // 仅当currentIndex有效（>=0且在模型范围内）时执行PLC指令
                if (currentIndex >= 0 && currentIndex < cutDataModel.count) {

                    Cpp_PLC.write_Modbus_RTU_Coils(142,"1")

                    // 获取当前选中项的数据
                    const currentItem = cutDataModel.get(currentIndex);
                    console.log("ListView换行，当前选中第" + (currentIndex + 1) + "行，执行PLC写入指令");        

                    console.log("写入 切割长度: "+currentItem.cutLength + " 左角度: "+currentItem.leftAngle + " 右角度: "+currentItem.rightAngle +" 切割数量: "+currentItem.cutCount)
                    if(Number(currentItem.cutLength) < Number(Cpp_PLC.ExtraShort_MaterialLengthMin))
                    {
                        // Cpp_OrderProcess.saveData((currentPacket*20 + 1),"MaterialLength",Cpp_PLC.ExtraShort_MaterialLengthMin)
                        // Cpp_OrderProcess.getDataByPacket(currentPacket)
                        Cpp_PLC.write_Modbus_RTU_Hold_32(1440,currentItem.cutLength)
                    }
                    else if(Number(currentItem.cutLength) > Number(Cpp_PLC.ExtraLong_MaterialLengthMax))
                    {
                        // Cpp_OrderProcess.saveData((currentPacket*20 + 1),"MaterialLength",Cpp_PLC.ExtraLong_MaterialLengthMax)
                        // Cpp_OrderProcess.getDataByPacket(currentPacket)
                        Cpp_PLC.write_Modbus_RTU_Hold_32(1440,currentItem.cutLength)
                    }
                    else
                    {
                        // Cpp_OrderProcess.saveData((currentPacket*20 + 1),"MaterialLength",inputData)
                        // Cpp_OrderProcess.getDataByPacket(currentPacket)
                        Cpp_PLC.write_Modbus_RTU_Hold_32(1440,currentItem.cutLength)
                    }

                    if(currentItem.leftAngle === 45)
                    {
                        // Cpp_OrderProcess.saveData((currentPacket*20+1),"LeftAngle","90")
                        Cpp_PLC.write_Modbus_RTU_Hold_16(1520,"0");
                    }
                    else if(currentItem.leftAngle === 90)
                    {
                        // Cpp_OrderProcess.saveData((currentPacket*20+1),"LeftAngle","45")
                        Cpp_PLC.write_Modbus_RTU_Hold_16(1520,"1");
                    }

                    if(currentItem.rightAngle === 45)
                    {
                        // Cpp_OrderProcess.saveData((currentPacket*20+1),"RightAngle","90")
                        Cpp_PLC.write_Modbus_RTU_Hold_16(1521,"0");
                    }
                    else if(currentItem.rightAngle === 90)
                    {
                        // Cpp_OrderProcess.saveData((currentPacket*20+1),"RightAngle","45")
                        Cpp_PLC.write_Modbus_RTU_Hold_16(1521,"1");
                    }

                    Cpp_PLC.write_Modbus_RTU_Hold_16(1480,currentItem.cutCount)
                    // 当前数量写入 D66
                    Cpp_PLC.write_Modbus_RTU_Hold_16(66,currentItem.cutCount)
                    // 当前已加工数量 写入 D231
                    Cpp_PLC.write_Modbus_RTU_Hold_16(231,currentItem.workedCount)

                    Cpp_PLC.write_Modbus_RTU_Hold_16(76,"1")
                    // Cpp_PLC.write_Modbus_RTU_Coils(172,0)
                    if(Cpp_PLC.MechineChangeAngleMode)
                    {
                        Cpp_PLC.write_Modbus_RTU_Coils(140,1)
                        Cpp_PLC.write_Modbus_RTU_Coils(141,1)
                    }
                    else
                    {
                        Cpp_PLC.write_Modbus_RTU_Coils(140,1)
                        Cpp_PLC.write_Modbus_RTU_Coils(141,1)
                        Cpp_PLC.write_Modbus_RTU_Coils(140,0)
                        Cpp_PLC.write_Modbus_RTU_Coils(141,0)
                    }

                } else {
                    console.log("无有效选中项，不执行PLC写入");
                }
            }

            delegate:
                Item {
                // id: name
                width: listView.width  // 宽度绑定到ListView
                height: 60
                // 绑定模型属性到本地，用于监听变化
                property int currentWorkedCount: workedCount
                property int currentCutCount: cutCount
                property int currentIndex: index

                // 监听已切数量变化
                onCurrentWorkedCountChanged: {
                    checkCompletion();
                }

                // 监听切割数量变化
                onCurrentCutCountChanged: {
                    checkCompletion();
                }

                // 检查完成逻辑（添加自动换行开关控制）
                function checkCompletion() {
                    if (currentCutCount === currentWorkedCount && currentCutCount !== 0) {
                        console.log("第" + (currentIndex + 1) + "行已完成");
                        if (listView.currentIndex === currentIndex) {
                            // 核心修改：只有启用自动换行时才执行自动移动
                            if (autoWrapEnabled) {
                                listView.moveToNextValidRow(currentIndex);
                            } else {
                                console.log("自动换行已禁用，保持当前选中状态");
                            }
                        }
                        listView.checkAndShowCompletionDialog();
                    }
                }

                Row {
                    id: dataRow
                    height: parent.height

                    // 序号列
                    Rectangle {
                        width: 70
                        height: parent.height
                        color: (currentCutCount === currentWorkedCount && currentCutCount !== 0) ? "#ffcccc"
                                : (listView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"
                        Text {
                            anchors.centerIn: parent
                            text: (currentIndex + 1)
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }

                    // 订单编号列
                    Rectangle {
                        width: 120
                        height: parent.height
                        color: (currentCutCount === currentWorkedCount && currentCutCount !== 0) ? "#ffcccc"
                              : (listView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"

                        Text {
                            id: orderCodeText
                            anchors.centerIn: parent
                            text: orderCode
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }

                    // 型材类型列
                    Rectangle {
                        width: 90
                        height: parent.height
                        color: (currentCutCount === currentWorkedCount && currentCutCount !== 0) ? "#ffcccc"
                                : (listView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"

                        Text {
                            id: profileTypeText
                            anchors.centerIn: parent
                            text: profileType
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }

                    }

                    // 产品名称列
                    Rectangle {
                        width: 120
                        height: parent.height
                        color: (currentCutCount === currentWorkedCount && currentCutCount !== 0) ? "#ffcccc"
                                : (listView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"

                        Text {
                            id: productNameText
                            anchors.centerIn: parent
                            text: productName
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }

                    }

                    // 颜色列（宽度调整为140）
                    Rectangle {
                        width: 140
                        height: parent.height
                        color: (currentCutCount === currentWorkedCount && currentCutCount !== 0) ? "#ffcccc"
                                                                                                 : (listView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"

                        Text {
                            id: colorText
                            anchors.centerIn: parent
                            text: materialcolor
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8  // 适应更宽的列，提供更多显示空间
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }

                    // 原料长度列
                    Rectangle {
                        width: 80
                        height: parent.height
                        color: (currentCutCount === currentWorkedCount && currentCutCount !== 0) ? "#ffcccc"
                                : (listView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"
                        Text {
                            anchors.centerIn: parent
                            text: materialLength
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }

                    // 切割长度列
                    Rectangle {
                        width: 140
                        height: parent.height
                        color: (currentCutCount === currentWorkedCount && currentCutCount !== 0) ? "#ffcccc"
                            : (listView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"
                        Text {
                            anchors.centerIn: parent
                            text: cutLength.toFixed(2)
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }

                    // 左角度列
                    Rectangle {
                        width: 70
                        height: parent.height
                        color: (currentCutCount === currentWorkedCount && currentCutCount !== 0) ? "#ffcccc"
                            : (listView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"
                        Text {
                            anchors.centerIn: parent
                            text: leftAngle + "°"
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }

                    // 右角度列
                    Rectangle {
                        width: 70
                        height: parent.height
                        color: (currentCutCount === currentWorkedCount && currentCutCount !== 0) ? "#ffcccc"
                             : (listView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"
                        Text {
                            anchors.centerIn: parent
                            text: rightAngle + "°"
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }

                    // 切割数量列
                    Rectangle {
                        width: 90
                        height: parent.height
                        color: (currentCutCount === currentWorkedCount && currentCutCount !== 0) ? "#ffcccc"
                            : (listView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"
                        Text {
                            anchors.centerIn: parent
                            text: currentCutCount
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }

                    // 已切数量列
                    Rectangle {
                        width: 90
                        height: parent.height
                        color: (currentCutCount === currentWorkedCount && currentCutCount !== 0) ? "#ffcccc"
                            : (listView.currentIndex === currentIndex ? "gold" : "white")
                        border.color: "#eeeeee"
                        Text {
                            anchors.centerIn: parent
                            text: currentWorkedCount
                            font.pixelSize: 15
                            elide: Text.ElideRight
                            width: parent.width - 8
                            horizontalAlignment: Text.AlignHCenter
                        }
                    }
                }

                MouseArea {
                    width: dataRow.width
                    height: dataRow.height
                    onClicked: {
                        // 点击时如果是已完成行则不选中，否则正常选中
                        if (!listView.checkComplete(currentIndex)) {
                            listView.currentIndex = currentIndex;
                            console.log("选中第" + (currentIndex + 1) + "行");
                        } else {
                            console.log("第" + (currentIndex + 1) + "行已完成，不允许选中");
                        }
                    }
                }

            }

            // 滚动条（确保能控制完整滚动）
            ScrollBar.vertical: ScrollBar {
                policy: ScrollBar.AlwaysOn
                width: 10
                // 绑定滚动条到ListView的可视区域和内容区域
                anchors.top: parent.top
                anchors.bottom: parent.bottom
                anchors.right: parent.right
            }

            // 监听模型数据更新，重置选中状态
            Connections {
                target: cutDataModel
                function onModelDataUpdated() {
                    listView.currentIndex = -1;
                    console.log("Model数据已更新，取消选中状态（currentIndex = -1）");
                }
            }
        }

    }

    onPlc_X_13Changed: {
        if((plc_M96 === true && plc_X_13 === true)|| (plc_M97 === true && plc_X_13 === true))
        {
            //计数+1
            // console.log("计数加1！！！！！")
            const isComplete = listView.checkComplete(listView.currentIndex);
            if (isComplete) {
                console.log("第" + (listView.currentIndex + 1) + "行已完成，不更新已切数量");
                return;
            }
            cutDataModel.incrementWorkedCount(listView.currentIndex);
            var updatedItem = cutDataModel.get(listView.currentIndex);
            console.log("已更新第" + (listView.currentIndex + 1) + "项，已切数量：" + updatedItem.workedCount);
            listView.checkAndShowCompletionDialog();
        }
        else
        {
            //不计数
            // console.log("不计数!")
            console.log("无有效选中项，不更新已切数量");
        }
    }

    onPlc_M61Changed:{
        if(plc_M61 === true)
        {
            //计数+1
            // console.log("计数加1！！！！！")
            const isComplete = listView.checkComplete(listView.currentIndex);
            if (isComplete) {
                console.log("第" + (listView.currentIndex + 1) + "行已完成，不更新已切数量");
                return;
            }
            cutDataModel.incrementWorkedCount(listView.currentIndex);
            var updatedItem = cutDataModel.get(listView.currentIndex);
            console.log("已更新第" + (listView.currentIndex + 1) + "项，已切数量：" + updatedItem.workedCount);
            listView.checkAndShowCompletionDialog();
        }
        else
        {
            //不计数
            // console.log("不计数!")
            console.log("无有效选中项，不更新已切数量");
        }
    }



    ComboBox {
        id : qrType_ComboBox
        anchors.top: netWorkProcessBack.top
        anchors.topMargin: 1600
        anchors.left: netWorkProcessBack.left
        anchors.leftMargin: 30
        width: 300
        height: 50

        currentIndex: (Cpp_Config.QR_Code_Type) === 6 ? 0 :
                      (Cpp_Config.QR_Code_Type) === 7 ? 1 :
                      (Cpp_Config.QR_Code_Type) === 8 ? 2 :
                      (Cpp_Config.QR_Code_Type) === 9 ? 3 : -1
        // 模型数据
        model: ListModel {
            // id: comboModel
            // ListElement{name:qsTr("长风离线")}
            // ListElement{name:qsTr("速制离线")}
            // ListElement{name:qsTr("画门窗离线")}
            // ListElement{name:qsTr("创品离线")}
            // ListElement{name:qsTr("新格尔离线")}
            ListElement{name:qsTr("长风在线")}
            ListElement{name:qsTr("新格尔在线")}
            ListElement{name:qsTr("速制在线")}
            ListElement{name:qsTr("创品在线")}
        }

        property string customDisplayText: model.get(currentIndex).name

        // 显示文本覆盖
        contentItem: Text {
            text: qrType_ComboBox.customDisplayText
            font.pixelSize: Cpp_Config.Language_Type === 1 ? 26 :  Cpp_Config.Language_Type === 2 ? 20 : 20
            color: qrType_ComboBox.currentIndex >= 0 &&
                   qrType_ComboBox.model.get(qrType_ComboBox.currentIndex).premium ?
                       premiumColor : "#2c3e50"
            horizontalAlignment: Text.AlignLeft
            verticalAlignment: Text.AlignVCenter
            leftPadding: 20
            elide: Text.ElideRight
            font.bold: true
        }

        // 背景样式
        background: Rectangle {
            border.width: 3
            radius: 12

            // 当ComboBox打开时改变样式
            color: qrType_ComboBox.popup.visible ? "#f0f8ff" : "#ffffff"
            border.color: qrType_ComboBox.popup.visible ? "#3498db" : (qrType_ComboBox.hovered ? "#3498db" : "#bdc3c7")
        }

        // 下拉指示器
        indicator: Canvas {
            x: qrType_ComboBox.width - width - 20
            y: qrType_ComboBox.topPadding + (qrType_ComboBox.availableHeight - height) / 2
            width: 24
            height: 14
            contextType: "2d"

            onPaint: {
                context.reset();
                context.moveTo(0, 0);
                context.lineTo(width, 0);
                context.lineTo(width / 2, height);
                context.closePath();
                context.fillStyle = qrType_ComboBox.popup.visible ? "#3498db" : "#7f8c8d";
                context.fill();
            }
        }

        // 下拉菜单（高度200px）
        popup: Popup {
            y: qrType_ComboBox.height + 10
            width: qrType_ComboBox.width
            implicitHeight: 200
            // padding: 2

            contentItem: ListView {
                clip: true
                implicitHeight: contentHeight
                model: qrType_ComboBox.popup.visible ? qrType_ComboBox.delegateModel : null
                currentIndex: qrType_ComboBox.highlightedIndex
                boundsBehavior: Flickable.StopAtBounds
            }

            background: Rectangle {
                color: "#ffffff"
                border.color: "#3498db"
                border.width: 2
                radius: 12
                layer.enabled: true
                layer.effect: DropShadow {
                    radius: 12
                    color: "#40000000"
                    samples: 20
                }
            }
        }

        // 下拉项委托
        delegate: ItemDelegate {
            width: qrType_ComboBox.width
            height: 60
            hoverEnabled: true

            // 名称（大字体）
            Text {
                text: model.name
                font.pixelSize: Cpp_Config.Language_Type === 1 ? 35 :  Cpp_Config.Language_Type === 2 ? 20 : 20
                color: model.premium ? premiumColor : "#2c3e50"
                font.bold: true
                anchors.verticalCenter:  parent.verticalCenter
                anchors.left: parent.left
                anchors.leftMargin: 20
            }

        }


        onActivated: {
            console.log(model.get(currentIndex).name)
            // Cpp_Scanner.Current_QR_Type = currentIndex+1
            if(currentIndex+1 === 1)
            {
                Cpp_Scanner.Current_QR_Type = 6
                Cpp_Config.QR_Code_Type = 6
            }
            else if(currentIndex+1 === 2)
            {
                Cpp_Scanner.Current_QR_Type = 7
                Cpp_Config.QR_Code_Type = 7
            }
            else if(currentIndex+1 === 3)
            {
                Cpp_Scanner.Current_QR_Type = 8
                Cpp_Config.QR_Code_Type = 8
            }
            else if(currentIndex+1 === 4)
            {
                Cpp_Scanner.Current_QR_Type = 9
                Cpp_Config.QR_Code_Type = 9
            }
        }

    }

    CheckBox {
        id: autoWrapCheckBox
        anchors.top: netWorkProcessBack.top
        anchors.topMargin: 1600
        anchors.right: netWorkProcessBack.right
        anchors.rightMargin: 20
        text: qsTr("启用自动换行")
        checked: autoWrapEnabled
        font.pixelSize: 16
        font.bold: true

        // 绑定自动换行功能开关状态
        onCheckedChanged: {
            autoWrapEnabled = checked;
            console.log("自动换行功能" + (checked ? "启用" : "禁用"));
        }
    }

}
